#ifndef LIDAR_HPP
#define LIDAR_HPP
#include <glog/logging.h>
#include <ros/ros.h>
// #include <sensor_msgs/Lidar.h>
#include <mutex>
#include <sensor_msgs/Range.h>
#include <std_srvs/SetBool.h>

#include "serial.hpp"
#pragma pack(1)
struct LidarData {
    uint8_t intensity;
    uint16_t range;
};

struct LidarFrameHead {
    uint16_t header; // 2
    uint16_t size;   // 2
    uint16_t start;  // 2
    uint16_t scope;  // 2
};

struct LidarFrameTail {
    uint16_t crc; // 2
};

struct LidarStatusFrame {
    uint16_t header;
    uint8_t config;
    uint8_t rotation;
    uint8_t reserved;
    uint8_t status;
    uint16_t end;
};

#pragma pack()

class Lidar : public Serial {
  public:
    Lidar(std::shared_ptr<ros::NodeHandle> node_handle_ptr,
          const std::string &serial_port);
    ~Lidar() = default;
    Lidar(const Lidar &) = default;
    Lidar &operator=(const Lidar &) = default;

    void LidarRxThread();

    void ParseData(std::vector<uint8_t> &data);

    //   void Publish(const sensor_msgs::Lidar &imu);

    bool SetRunning(const bool &running);

    bool SwitchCallBack(std_srvs::SetBool::Request &req,
                        std_srvs::SetBool::Response &res);

  private:
    std::shared_ptr<ros::NodeHandle> node_handle_ptr_;
    ros::Publisher publisher_;
    ros::ServiceServer switch_;
    std::string name_;
    bool is_running_{false}; // 程序是否运行
    bool is_start_{false};   // 硬件是否运行
    // bool is_right_bandrate_{false};
    std::vector<ros::Time> times_;
    // std::mutex mutex_;
};
#endif